﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.IBusiness.IOrderModule;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Core.ApiClient.Controllers.Order
{
    /// <summary>
    /// 优惠卷
    /// </summary>
    [Route(".v1/Order/[controller]")]
    [ApiController]
    [ApiVerification(IBusiness.IProjectModule.Model.APIServiceEnum.Shop)]
    public class OrderCouponController : BaseApiController
    {
        public OrderCouponController(IOrderCoupon iOrderCoupon) :
            base(iOrderCoupon: iOrderCoupon)
        {

        }

        /// <summary>
        /// 查询指定优惠卷
        /// </summary>
        /// <param name="code">优惠卷码</param>
        /// <returns></returns>
        [HttpGet("{code}")]
        public IResult GetOrderCouponByCode(string code)
        {

            return this.ExecMethod(
                  () => {
                      return this.Result(this.iOrderCoupon.GetOrderCouponByCode(code));
                  }, 
                  new Tuple<bool, string>(
                      code.Length > 5 || code.Length < 9,
                      "输入的优惠卷码不正确")
                  );
        }

    }
}